#include "iostream"
using namespace std;

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
 struct ListNode{
     int val;
     ListNode *next;
     ListNode(int x):val(x),next(NULL){}
 };
ListNode* deleteNode(ListNode* head, int val) {
    ListNode *p,*q;
    p=head->next;
    q=head;
    if(head->val==val){
        head=head->next;
        return head;
    }

    while(head->next!=NULL){
        if (p->val==val){
            break;
        }
        p=p->next;
        q=q->next;
    }
    q->next=p->next;
    p->next=NULL;
    return head;

}

